package org.zht.dormpro.dorm.activemq;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j;
import org.apache.activemq.command.ActiveMQTextMessage;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

@Log4j
public class Receiver implements MessageListener {
    @Override
    public void onMessage(Message message) {
        if(message!=null){
            ActiveMQTextMessage objectMessage = (ActiveMQTextMessage) message;
            JSONObject object = null;
            try {
                object = JSONObject.parseObject(objectMessage.getText());
            } catch (JMSException e) {
                log.error(e,e);
            }
            log.info(object.toJSONString());
        }
    }
}
